package cn.wx.shop.web.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.wx.shop.entity.SysUser;
import cn.wx.shop.service.SysUserService;

@Controller
public class LoginController {

	@Autowired
	SysUserService sysUserService;
	
	/**
	 * 管理员登录
	 * @param username 用户名
	 * @param password 密码
	 * @param model
	 * @param session
	 * @return
	 */
	@RequestMapping("/sysLogin")
	public String login(String username,String password,Model model,HttpSession session){
		
		SysUser sysUser = sysUserService.login(username, password);
		if(sysUser !=null){
			//登录成功
			session.setAttribute("sysUser", sysUser);
			return "index";
		}
		model.addAttribute("error", "用户名密码错误!");
		return "login";
	}
}
